package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.climbtower.ClimbTowerMgr;

import java.util.ArrayList;
import java.util.List;

public class ClimbTowerRecycleStrategy extends AbstractItemRecycleStrategy {


    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = ClimbTowerMgr.getActivityInfo();
        if(activityInfo != null){
            //回收体力道具（道具转积分）
            addRecycleItemData(activityInfo, ClimbTowerMgr.getConfig().getAddAuraItemId());
            //回收其他道具
        }
    }

    //转积分的约定，
    private void addRecycleItemData(ActivityInfo activityInfo, int itemId) {
        List<String> paramList = new ArrayList<>();
        //回收时间
        long recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
        //参数1：待回收道具
        paramList.add(String.valueOf(itemId));
        //参数2：积分道具
        paramList.add(String.valueOf(ClimbTowerMgr.getConfig().getScoreItemId()));
        //参数3：1个道具转换多少倍积分，这边 2 指 itemId 远程道具配置表 GoodsInfo paramList 的下标
        paramList.add("2");
        //参数4：活动名称
        paramList.add(activityInfo.getActivityName());
        //新增一条回收规则
        ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 3, recycleTime, paramList);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.ClimbTower.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        String titleKey = MailManager.ACTIVITY_GOODS_AUTO_CONSUME_TITLE;
        String contentKey = MailManager.ACTIVITY_GOODS_AUTO_CONSUME_CONTENT;
        item2Score(userId, data, titleKey, contentKey);
    }

    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = ClimbTowerMgr.getActivityInfo();
        if(activityInfo == null){
            ClimbTowerMgr.getLogger().error("ClimbTower Recycle Fail, Because ActivityInfo is null");
            return false;
        }
        return ActivityMgr.activityInTime(activityInfo);
    }
}
